import java.util.*;

/**
 * this class will do all the work ill need to do with the string
 **/
public class StringWorker{
	private static final String sep="LOGO>";//seperator String
	/**
	* I need to take a string and get the last command from it
 	* the String will be of the form 
 	* LOGO>FD 10
 	* LOGO>RT 90
 	* LOGO>FD 20
    * the function should be able to extract the last command
    *special cases:
    *1.repeat
    *2.commands 
	**/
	public static String lastCommand(String s){
		String command="";
		int i=s.lastIndexOf(sep);
		command=s.substring(i+sep.length());
		return command;
		}
	/**
	 *this function will return the command in the form of an arraylist
	 *with the command and values seperated.the seperator is space.
	 *So if you give LOGO>fd 10 rt 10 you will get back [fd, 10, rt, 10]
	 **/
	public static List lastCommandArr(String s){
		List l=new ArrayList();
		try{
	    String temp;
	    String command=s;
	    boolean last=false;
	    while(command.length()>0){
	    	int i=command.indexOf(" ");
	    	if(i==-1){
	    		i=command.length();
	    		last=true;
	    		}
	    	temp=command.substring(0,i);
	    	l.add(temp);
	    	command=command.substring(i+1);
	    	if(last){
	    		break;
	    		}
	    	}
	    }catch(StringIndexOutOfBoundsException e){}
	    String s1=(String)l.get(0);
	    if(s1.equals("repeat")){
	    	String[] sArr=new String[2];
	    	String ss=(String)l.get(1);
	    	int i=ss.indexOf("(");
	    	sArr[0]=ss.substring(0,i);
	    	sArr[1]=ss.substring(i+1);
	    	l.set(1,sArr[0]);
	    	l.add(2,sArr[1]);
	    	for(Iterator ii=l.iterator();ii.hasNext();){
	    		ss=(String)ii.next();
	    		}
	    	i=ss.indexOf(")");
	    	ss=ss.substring(0,i);
	    	l.remove(l.size()-1);
	    	l.add(ss);
	    	}
	    return l;	    
		}
	public static void main(String[] args){
		String str="LOGO>FD 10\nLOGO>fd 10 rt 10";
		System.out.println(str);
		String str1=lastCommand(str);
		List l=lastCommandArr(str1);
		System.out.println(l);
		}
	
	}